package com.tms.admin.controller;


import com.tms.admin.entity.TmsCustomer;
import com.tms.admin.entity.TmsDriver;
import com.tms.admin.entity.vo.CustomerQueryVO;
import com.tms.admin.entity.vo.DriverQueryVO;
import com.tms.admin.service.TmsCustomerService;
import com.tms.common.entity.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "顾客管理")
@RestController
@RequestMapping("/customer")
@CrossOrigin
public class CustomerController {
    @Autowired
    private TmsCustomerService customerService;

    @ApiOperation(value = "根据查询条件分页/模糊查询顾客信息")
    @PostMapping("page")
    public ResultVO getDriverPage(@RequestBody CustomerQueryVO customerQueryVO){
        Map<String, Object> map = customerService.getPageByCondition(customerQueryVO);
        return ResultVO.ok().data("pageInfo", map);
    }

    @ApiOperation(value = "新增顾客")
    @PostMapping
    public ResultVO addCustomer(@RequestBody TmsCustomer customer){
        customerService.addCustomer(customer);
        return ResultVO.ok();
    }

    @ApiOperation(value = "删除顾客")
    @DeleteMapping
    public ResultVO removeCustomersById(@RequestBody List<Integer> customerIds){
        customerService.removeCustomersById(customerIds);
        return ResultVO.ok();
    }

    @ApiOperation(value = "修改顾客信息")
    @PutMapping
    public ResultVO modifyCustomerById(@RequestBody TmsCustomer customer){
        customerService.modifyCustomerById(customer);
        return ResultVO.ok();
    }

    @ApiOperation(value = "查询所有的顾客")
    @GetMapping
    public ResultVO getList(){
        List<TmsCustomer> list = customerService.list();
        return ResultVO.ok().data("items", list);
    }
}
